package com.acyouzi.leetcode.array;

/**
 * 17/9/13 19:30
 *
 * @author sunxu
 */
public class NonDecreasing {
  public boolean checkPossibility(int[] nums) {
    int cnt = 0;
    for (int i = 1; i < nums.length; i++) {
      if (nums[i] < nums[i-1]){
        cnt ++;
        if (i - 2 < 0 || nums[i-2] <= nums[i]){
          nums[i-1] = nums[i];
        }else{
          nums[i] = nums[i-1];
        }
      }
    }
    return cnt <= 1;
  }
}
